<?php

namespace app\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\Parents;

/**
 * ParentsSearch represents the model behind the search form about `app\models\Parents`.
 */
class ParentsSearch extends Parents
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['jz_id', 'xs_id', 'yey_id', 'bj_id'], 'integer'],
            [['jz_name', 'jz_wxm', 'jz_wxtx', 'xs_gx', 'xiugai_shijian', 'xiugai_ren'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = Parents::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'jz_id' => $this->jz_id,
            'xs_id' => $this->xs_id,
            'yey_id' => $this->yey_id,
            'bj_id' => $this->bj_id,
            'xiugai_shijian' => $this->xiugai_shijian,
        ]);

        $query->andFilterWhere(['like', 'jz_name', $this->jz_name])
            ->andFilterWhere(['like', 'jz_wxm', $this->jz_wxm])
            ->andFilterWhere(['like', 'jz_wxtx', $this->jz_wxtx])
            ->andFilterWhere(['like', 'xs_gx', $this->xs_gx])
            ->andFilterWhere(['like', 'xiugai_ren', $this->xiugai_ren]);

        return $dataProvider;
    }
}
